package com.handpay.nocardpay.baselibrary.http;

import com.android.volley.RetryPolicy;
import com.android.volley.VolleyError;

/**
 * @author sxshi on 2017/3/17.
 *  email:emotiona_xiaoshi@126.com
 * describe:重写Volley的重连机制，防止扫码支付交易遇到网络请求失败的时候重连机制，生成一笔重复的订单
 */

public class CustomRetryPolicy implements RetryPolicy {
    /**
     * The current timeout in milliseconds.
     */
    private int mCurrentTimeoutMs;
    /**
     * The default socket timeout in milliseconds
     */
    public static final int DEFAULT_TIMEOUT_MS = 90 * 1000;

    @Override
    public int getCurrentTimeout() {
        return 0;
    }

    @Override
    public int getCurrentRetryCount() {
        return 0;
    }

    @Override
    public void retry(VolleyError error) throws VolleyError {
        float mBackoffMultiplier = 0;
        mCurrentTimeoutMs += (mCurrentTimeoutMs * mBackoffMultiplier);
        if (!hasAttemptRemaining()) {
            throw error;
        }
    }

    /**
     * Returns true if this policy has attempts remaining, false otherwise.
     */
    protected boolean hasAttemptRemaining() {
        /*
      The maximum number of attempts.
     */
        int mMaxNumRetries = 0;
        return true;
    }

    public CustomRetryPolicy() {
        this(DEFAULT_TIMEOUT_MS);
    }

    public CustomRetryPolicy(int initialTimeoutMs) {
        this.mCurrentTimeoutMs = initialTimeoutMs;
    }
}
